////////////////////////////////////////////////////////////////////////////////
//
// Licensed under the MIT License
//
// Copyright (c) 2008 Chris Colinsky
// All Rights Reserved
//
// version	0.4
// http://code.google.com/p/sugarcookie/
// http://code.google.com/p/sugarcookie/wiki/License
//
////////////////////////////////////////////////////////////////////////////////

import sugarcookie.events.Event;
import sugarcookie.logger.Logger;
import sugarcookie.utils.ObjectUtil;

import mx.events.EventDispatcher;

dynamic class sugarcookie.dataHandlers.LoadVarsReturnHandler extends LoadVars {
	public function LoadVarsReturnHandler() {
		EventDispatcher.initialize(this);
	}
	
	public function onLoad(success:Boolean):Void {
		postEvent("onLoadVarsReturn",null,success,true,this);
	}
	
	public function postEvent(evt:String, msg:String, status:Boolean, isLogable:Boolean, data:Object):Void {
		var e:Event = new Event();
		e.target = _target;
		e.type   = evt;
		e.msg = msg!=undefined?msg:null;
		e.status = status!=undefined?status:null;
		e.data   = data!=undefined?data:null;
		
		if (isLogable) {
			var str:String = "Event - type: "+evt;
			if (msg.length>0 && msg!=null) str += ", msg: "+msg;
			if (status!=null) str += ", status: "+status;
			if (data!=null || data!=undefined) str += ", data:\n"+ObjectUtil.explode(data);
			_log.event(str);
		}
		
		dispatchEvent(e);
	}
	
	private function dispatchEvent() {};
	public  function addEventListener() {};
	public  function removeEventListener() {};
}